<template>
  <div>
    <van-nav-bar
        title="收货地址"
        left-text="返回"
        right-text="新增地址"
        left-arrow
        @click-left="$router.push(`/Me`)"
        @click-right="onClickRight"
        />
      <van-empty image="error" 
                 v-if="this.list.length==0"  
                 description="暂无收货地址哦" />
     <van-address-list
        v-else
        v-model="chosenAddressId"
        :list="list"
        :disabled-list="disabledList"
        disabled-text="以下地址超出配送范围"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
    />   
     
  </div>  
</template>
<script>
import { Toast } from "vant";
import { constants } from "os";
import { connect } from "tls";
export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [],
      disabledList: [
        {
          id: "3",
          name: "YX",
          tel: "1320000000",
          address: "广东省省深圳市龙华区"
        }
      ]
    };
  },
  created() {
    //获取地址对象
    let Add = this.$store.state.list;
    this.list.push(...Add);
    //遍历素组，默认选中同步
    this.list.forEach(item => {
      if (item.isDefault == true) {
        this.chosenAddressId = item.id;
      }
    });
    // console.log(this.list.length);
  },
  methods: {
    onClickRight() {
      this.$router.push(`/add`);
    },
    onAdd() {
      Toast("新增地址");
      this.$router.push(`/add`);
    },
    onEdit(item, index) {
      Toast("编辑地址:" + index);
    }
  }
};
</script>
